<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'tour-form',
	'enableAjaxValidation'=>false,
));

    $minYear = date('Y');
    $maxYear = $minYear + 5;

    Yii::app()->clientScript->registerScript('show_datapickers', "
         $('#Tour_beginning_date').datepicker({
            showAnim: 'fadeIn',
            changeMonth: true,
            changeYear: true,
            minDate: new Date() ,
            yearRange: '$minYear:$maxYear'
        });

        $('#Tour_end_date').datepicker({
            showAnim: 'fadeIn',
            changeMonth: true,
            changeYear: true,
            minDate: new Date() ,
            yearRange: '$minYear:$maxYear'
        });
    ");

    if(!isset($update_mode)){
        $update_mode = false;
    }

    ?>

	<p class="note">Обязательные поля <span class="required">*</span></p>

	<?php echo $form->errorSummary($model); ?>



	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>150)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'description'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'locality_id'); ?>
		<? echo CHtml::activeDropDownList($model, 'locality_id', CHtml::listData(Locality::model()->findAll(), 'id', 'city', 'country'));?>
		<?php echo $form->error($model,'locality_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'beginning_date'); ?>
		<?php echo $form->textField($model,'beginning_date',array('size'=>10,'maxlength'=>10)); ?>
		<?php echo $form->error($model,'beginning_date'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'end_date'); ?>
		<?php echo $form->textField($model,'end_date',array('size'=>10,'maxlength'=>10)); ?>
		<?php echo $form->error($model,'end_date'); ?>
	</div>

    <div class="row">
		<?php echo $form->labelEx($model,'price'); ?>
		<?php echo $form->textField($model,'price',array('size'=>10,'maxlength'=>10)); ?>
		<?php echo $form->error($model,'price'); ?>
	</div>

    <?
        if($update_mode):

            echo "<br/><h1>Фотографии</h1>";
            $photo_model = new Photo();

            $this->widget('zii.widgets.grid.CGridView', array(
                'id'=>'photo-grid',
                'dataProvider'=>$photo_model->searchForTour($model->id),
                'filter'=>$photo_model,
                'columns'=>array(
                    array(
                        'name'=>'path_to_thumb',
                        'type'=>'image',
                        'value'=> '$data->path_to_thumb',
                        'htmlOptions'=>array('class'=>'avatar'),
                    ),
                    'description',
                    array(
                        'class'=>'CButtonColumn',
                        'template'=>'{update} {delete}',
                        'updateButtonUrl'=>'Yii::app()->controller->createUrl("photo/update",array("id"=>$data->primaryKey, "return_url"=>"'.$return_url.'"))',
                        'deleteButtonUrl'=>'Yii::app()->controller->createUrl("photo/delete",array("id"=>$data->primaryKey))',
                    ),
                ),
            ));

            echo "<br/><h1>Комментарии</h1>";
            $comment_model = new Comment();

            $this->widget('zii.widgets.grid.CGridView', array(
                'id'=>'comment-grid',
                'dataProvider'=>$comment_model->searchForTour($model->id),
                'filter'=>$comment_model,
                'columns'=>array(
                    array(
                        'name'=>'user_id',
                        'value'=> '$data->getUser()->username',
                        'htmlOptions'=>array('class'=>'avatar'),
                    ),
                    'publication_date',
                    'header',
                    'content',
                    array(
                        'class'=>'CButtonColumn',
                        'template'=>'{delete}',
                        'deleteButtonUrl'=>'Yii::app()->controller->createUrl("comment/delete",array("id"=>$data->primaryKey))',
                    ),
                ),
            ));
        endif;
    ?>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Продолжить' : 'Сохранить'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->